package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.GalleryExample;
import it.irondev.appturismo.dao.provider.GallerySqlProvider;
import it.irondev.appturismo.entity.Gallery;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface GalleryMapper {
    @SelectProvider(type=GallerySqlProvider.class, method="countByExample")
    int countByExample(GalleryExample example);

    @DeleteProvider(type=GallerySqlProvider.class, method="deleteByExample")
    int deleteByExample(GalleryExample example);

    @Delete({
        "delete from Gallery",
        "where idGallery = #{idgallery,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idgallery);

    @Insert({
        "insert into Gallery (idGallery, name, ",
        "description)",
        "values (#{idgallery,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=INTEGER})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idgallery")
    int insert(Gallery record);

    @InsertProvider(type=GallerySqlProvider.class, method="insertSelective")
    int insertSelective(Gallery record);

    @SelectProvider(type=GallerySqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idGallery", property="idgallery", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.INTEGER)
    })
    List<Gallery> selectByExample(GalleryExample example);

    @Select({
        "select",
        "idGallery, name, description",
        "from Gallery",
        "where idGallery = #{idgallery,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idGallery", property="idgallery", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.INTEGER),
		@Result(column="idGallery",property="medias", javaType=List.class, many=@Many(select="it.irondev.appturismo.dao.MediaMapper.selectByGalleryId"))

    })
    Gallery selectByPrimaryKey(Integer idgallery);

    @UpdateProvider(type=GallerySqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Gallery record, @Param("example") GalleryExample example);

    @UpdateProvider(type=GallerySqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Gallery record, @Param("example") GalleryExample example);

    @UpdateProvider(type=GallerySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Gallery record);

    @Update({
        "update Gallery",
        "set name = #{name,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=INTEGER}",
        "where idGallery = #{idgallery,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Gallery record);
}